package com.hao.array;

/**
 * TODO
 *
 * @author 97472
 * @version 1.0
 * @date 2021/4/15 14:56
 */
public class ArrQueue implements Queue{

    private static final int QUEUE_MAX_SIZE = 500;
    private static final int FRONT_INITIAL_VALUE = -1;
    private static final int REAR_INITIAL_VALUE = -1;
    private static final int SIZE_INITIAL_VALUE = 0;

    private int[] queue = new int[QUEUE_MAX_SIZE];
    private int front = FRONT_INITIAL_VALUE;
    private int rear = REAR_INITIAL_VALUE;
    private int size = SIZE_INITIAL_VALUE;
    public void push(int i) {
        if (rear<QUEUE_MAX_SIZE){
            rear++;
            size++;
            queue[rear] = i;
        }else {
            throw new RuntimeException("队列已经溢出");
        }
    }

    public int pop() {
        if (front<rear){
            front++;
            size--;
            return queue[front];
        }else {
            throw new RuntimeException("队列为空");
        }
    }

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public int getFront() {
        if (front<rear){
            return queue[front+1];
        }else {
            throw new RuntimeException("队列为空");
        }
    }
}
